﻿/*!
 * Ext JS Library 4.2 -- Lyh.container.Main
 * Copyright(c) 2014 lyh Inc.
 * logyou@msn.com
 * http://extjs.codeplex.com/
 */

Ext.define('Lyh.container.Main', {
    extend: 'Ext.container.Viewport',
    alias: 'main',
    layout: 'border',

    initComponent: function() {
        var me = this;

        me.topBar = Ext.create('Ext.toolbar.Toolbar', {
            region: 'north',
            height: 40,
            border: false,
            items: [
                {
                    text: 'Button'
                }
            ]
        });

        me.store = Ext.create('Ext.data.TreeStore', {
            autoLoad: true,
            defaultRootId: "0",
            nodeParam: 'parentId',
            proxy: {
                type: 'ajax',
                url: '/Menu/GetMenuTreeStore',
                reader: {
                    type: 'json'
                }
            },
            root: {
                id: '0',
                text: '我的菜单',
                expanded: true,
                level: 0
            }
        });

        me.leftMenu = Ext.create('Ext.tree.Panel', {
            region: 'west',
            title: '功能菜单',
            width: 200,
            collapsible: true,
            split: true,
            autoScroll: true,
            iconCls: 'plugin',
            store: me.store,
            listeners: {
                itemclick: function(tree, record) {
                    if (record.data.leaf == true) {
                        var tab = me.tabMain.getComponent('tab_' + record.raw.id);
                        if (!tab) {
                            tab = Ext.create('Ext.Panel', {
                                id: 'tab_' + record.raw.id,
                                closable: true,
                                title: record.raw.text,
                                iconCls: record.raw.iconCls,
                                autoScroll: true,
                                border: false,
                                layout: 'fit',
                                autoLoad: {
                                    url: record.raw.url,
                                    scope: me,
                                    scripts: true,
                                    text: '页面加载中，请稍候……'
                                }
                            });
                            me.tabMain.add(tab);
                        }
                        me.tabMain.setActiveTab(tab);
                    }
                }
            }
        });

        me.tabMain = Ext.create('Ext.tab.Panel', {
            id: 'tabMain',
            region: 'center',
            items: [
                {
                    closable: true,
                    iconCls: 'house',
                    title: '首页',
                    html: '欢迎！'
                }
            ]
        });

        me.footBar = Ext.create('Ext.ux.StatusBar', {
            region: 'south',
            border: false,
            cls: 'main-footBar',
            defaults: { cls: 'main-footBar' },
            items: ['->', 'hi,欢迎回来', '-', '上次登录时间：', '上次登录IP：', '-', '版本：v1.0', '-', '版权所有']
        });

        me.items = [me.topBar, me.leftMenu, me.tabMain, me.footBar];
        me.callParent();
    }
});

Ext.onReady(function() {
    Ext.create('main');
});